package com.cloud.control.service.core;

import org.apache.mina.core.session.IoSession;

import com.cloud.control.service.utils.JDBCUtils;
import com.cloud.control.service.utils.RSAUtils;

public class RegisterUser implements Runnable {
    private IoSession sessionFin;
	private String userid;
	private String name;
    
	@Override
	public void run() {
		//加密證書是用App加密證書加密，不是直接用DB證書加密的，防止數據庫被拖庫！
		String certificate=RSAUtils.encryptRSA(userid);
		int cnt=JDBCUtils.RegisterUser(userid,name);
		/*如果注册成功,应该更新了一条记录!*/
		if(cnt==1){
			sessionFin.write("proxy----certificate----"+certificate+"#");//向socket5 proxy server返回加密的证书！
		}else{
			sessionFin.write("proxy----failed#");
		}
	}

    public void setSessionFin(IoSession sessionFin) {
		this.sessionFin = sessionFin;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

}
